<!-- 我的底部 -->

<template>
  <div>
    <BtnPrimary v-if="hasSave" title="存草稿" plain @click="toSave" />
    <BtnPrimary v-if="hasPrev" title="上一步" :key="`prev${one.step}`" plain @click="toPrev" />
    <BtnPrimary v-if="hasNext" title="下一步" :key="`next${one.step}`" plain @click="toNext" />
    <BtnPrimary v-if="hasAdd" title="发　布" @click="toAdd" />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyFooter',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb('add')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 有无保存
     */
    hasSave() {
      return this.one.step > 1
    },

    /**
     * 有无上一步
     */
    hasPrev() {
      return this.one.step > 1
    },

    /**
     * 有无下一步
     */
    hasNext() {
      return this.one.step < 3
    },

    /**
     * 有无发布
     */
    hasAdd() {
      return this.one.step === 3
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 下一步
     */
    async toNext() {
      const { refForm, one } = this
      await refForm.check()
      one.step++
    },

    /**
     * 上一步
     */
    toPrev() {
      const { one } = this
      one.step--
    },

    /**
     * 保存
     */
    async toSave() {
      const { refForm, one, startAdd } = this
      await refForm.check()
      one.status = 'task_draft'
      one.operate = '保存草稿'
      startAdd()
    },

    /**
     * 发布
     */
    async toAdd() {
      const { refForm, one, startAdd } = this
      await refForm.check()
      one.status = one.resolverUserId ? 'task_receive' : 'task_assign'
      one.operate = '工单发布'
      startAdd()
    },
  },
}
</script>
